const express = require('express');
const app = express();
const path = require('path');
const fs = require('fs');
const db = require('./db')
    // const mysql = require('mysql');
    // const conn = mysql.createConnection({
    //     host: 'localhost',
    //     port: 3306,
    //     user: 'root',
    //     password: 'root',
    //     database: '汪佳慧是一坨屎'
    // });
    // conn.connect();


app.listen(3000, () => {
    console.log('服务器已ok');
});

// 第三方插件，解决跨域问题
const cors = require('cors');
app.use(cors());

//使用内置插件获取请求体
app.use(express.urlencoded({ extended: false }));


const bookpath = path.join(__dirname, 'books.json')
    // 获取书籍
    // console.log(bookpath)

const books = require(path.join(__dirname, 'router', 'book.js'))
app.use('/api', books)